﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.WebApi
{
    public class ActionResult
    {
        public bool IsSuccess { get; set; }

        public int ErrorCode { get; set; }

        public string Message { get; set; }

        public object Data { get; set; }

        public string ActionVersion { get; set; }

        public ActionResult(CPPEI.Result result)
        {
            IsSuccess = result.IsSuccess;
            ErrorCode = result.ErrorCode;
            Message = result.Message;
            ActionVersion = "1.0";
        }

        public ActionResult(bool isSccuess, int errorCode, string message, object data)
        {
            ActionVersion = "1.0";
            IsSuccess = isSccuess;
            ErrorCode = errorCode;
            Message = message;
            Data = data;
        }

        public ActionResult(string actionVersion, bool isSccuess, int errorCode, string message, object data)
        {
            this.ActionVersion = actionVersion;
            IsSuccess = isSccuess;
            ErrorCode = errorCode;
            Message = message;
            Data = data;
        }
    }

    public class ActionResult<T>
    {
        public bool IsSuccess { get; set; }

        public int ErrorCode { get; set; }

        public string Message { get; set; }

        public T Data { get; set; }

        public string ActionVersion { get; set; }

        /// <summary>
        /// 构造一个结果
        /// </summary>
        /// <param name="result"></param>
        public ActionResult(CPPEI.Result result)
        {
            this.ActionVersion = "1.0";
            IsSuccess = result.IsSuccess;
            ErrorCode = result.ErrorCode;
            Message = result.Message;
            Data = default(T);
        }

        public ActionResult(CPPEI.Result result, T data)
            : this(result)
        {
            Data = data;
        }

        /// <summary>
        /// 构造一个没有错误的结果
        /// </summary>
        /// <param name="version"></param>
        /// <param name="data"></param>
        public ActionResult(T data)
        {
            this.ActionVersion = "1.0";
            IsSuccess = true;
            ErrorCode = CPPEI.WebApi.ErrorCode.NoError;
            Message = CPPEI.WebApi.ErrorCode.ToString(ErrorCode);
            Data = data;
        }

        /// <summary>
        /// 构造一个没有错误的结果
        /// </summary>
        /// <param name="version"></param>
        /// <param name="data"></param>
        public ActionResult(string version, T data)
        {
            this.ActionVersion = version;
            IsSuccess = true;
            ErrorCode = CPPEI.WebApi.ErrorCode.NoError;
            Message = CPPEI.WebApi.ErrorCode.ToString(ErrorCode);
            Data = data;
        }

        public ActionResult(bool isSuccess, int errorCode, string message, T data)
        {
            this.ActionVersion = "1.0";
            IsSuccess = isSuccess;
            ErrorCode = errorCode;
            Message = message;
            Data = data;
        }
        public ActionResult(string actionVersion, bool isSuccess, int errorCode, string message, T data)
        {
            this.ActionVersion = actionVersion;
            IsSuccess = isSuccess;
            ErrorCode = errorCode;
            Message = message;
            Data = data;
        }
    }
}
